package com.rykj.base;


import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Description:自动取消请求的presenter 需要手动在页面onndestroy 调用detatch author: zhangsan on 16/11/21 下午5:28.
 */

public class RxPresenter<T extends MvpView> extends BasePresenter<T> {

    private CompositeSubscription mCompositeSubscription;

//    protected ApiService apiService;
//
//    public RxPresenter(ApiService apiService) {
//        this.apiService = apiService;
//    }

    protected void addSubscribe(Subscription subscription) {
        if (mCompositeSubscription == null) {
            mCompositeSubscription = new CompositeSubscription();
        }
        mCompositeSubscription.add(subscription);
    }

    @Override
    public void detachView() {
        unSubscribe();
        super.detachView();
    }

    public void unSubscribe() {
        if (mCompositeSubscription != null) {
            mCompositeSubscription.unsubscribe();
        }
    }
}
